package com.example.demo.controller;

import com.example.demo.entity.ShopCar;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletResponse;
import java.io.*;

/**
 * Created by liujiahao on 2018/11/28.
 */
@Controller
@RequestMapping("/ss")
public class mainController {
    @Autowired
    ShopCar shopCar;
    @Autowired
    StudentService service;
    @RequestMapping("/main")
    public String main(String name){
        //service.insert();
       /* if(name!=null){
            shopCar.setId(22l);
            shopCar.setName(name);
        }
        service.findById(name);*/
        //System.out.println(shopCar);
        return "main";
    }

    @RequestMapping("/api")
    public void getInterfaceFile(HttpServletResponse response)
            throws IOException {
        File file=new File("config"+File.separator+"api.json");
        BufferedInputStream in=new BufferedInputStream(new FileInputStream(file));
        InputStreamReader inputStreamReader = new InputStreamReader(in);
        BufferedReader reader = new BufferedReader(inputStreamReader);
        StringBuilder sb = new StringBuilder();
        String lineSeparator = System.getProperty("line.separator", "\n");
        String line;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
            sb.append(lineSeparator);
        }
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String result = sb.toString();
        out.print(new String(result.getBytes("UTF-8")));
        out.flush();
        out.close();
        reader.close();
    }
}
